<?php
/**
 * Created by PhpStorm.
 * User: Peco
 * Date: 2019/9/22
 * Time: 11:07
 */

namespace App\Models;


class UserAuctionRecord extends BaseModel
{
    /**
     * 与模型关联的数据表
     *
     * @var string
     */
    protected $table = 'user_auction_record';

    /**
     * 主键
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * 需要被转换成日期的属性。
     *
     * @var array
     */
    protected $dates = ['mark_up_time', 'updated_at'];

    /**
     * @var array
     */
    protected $guarded = ['id'];

    /**
     * 判断该竞拍记录的竞拍状态
     * @param $query
     * @param bool $status
     */
    public function scopeAuctionStatus($query, bool $status = HANDLE_SUCCESS){
        $query->where('status', $status);
    }

    /**
     * 所属用户信息
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function user(){
        return $this->belongsTo(User::class, 'userId', 'id')->select(['id', 'avatar', 'nickname', 'realname', 'phone']);
    }

    /**
     * 拍卖商品
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function auctionGoodsInfo(){
        return $this->belongsTo(AuctionGoodsInfo::class, 'auctionId', 'auctionId');
    }

    /**
     * 所属商品
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function goods(){
        return $this->belongsTo(Goods::class, 'goodsId', 'id');
    }

}
